package com.power.project.service.impl;

import cn.hutool.crypto.SmUtil;
import com.power.base.model.Ha_user;
import com.power.project.dao.Ww_userDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * 业务层实现
 */
@Service
public class AccountServiceImpl {

    @Resource
    private Ww_userDao dao;

    @Value("${power.user.salt:power8650sunny}")
    private String user_salt;

    /**
     * 添加用户
     * @param userId
     * @param password
     */
    @Transactional(rollbackFor = Exception.class)
    public void addUser(String userId, String password) {

        // 新增账号信息
        Assert.notNull(password, "密码不能为空");
        Ha_user user = new Ha_user();
        user.setUserid(userId);
        user.setPassword(SmUtil.sm3WithSalt(user_salt.getBytes()).digestHex(password).toLowerCase());

        dao.addUser(user);
    }
}
